package cn.ruituo.adv9;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class Book2Test4 {
    public static void main(String[] args) {
//        List<Book2> list = new ArrayList<>();
//        for (int i = 1; i <= 5; i++) {
//            Book2 b1= new Book2(i, "java核心第" + i + "卷", "邮电出版社", 30 + i);
//            for(int j=1;j<=3;j++) {
//                b1.getAuthors().add(new Author("Cao "+j,20+j,"第"+j+"副教授"));
//            }
//            list.add(b1);
//        }
//        try {
//            //xml序列化
//            XMLEncoder xd=new XMLEncoder(new FileOutputStream("books.xml"));
//            xd.writeObject(list);
//            xd.close();
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }

        try {
            XMLDecoder xf=new XMLDecoder(new FileInputStream("books.xml"));
            List<Book2> list= (List<Book2>) xf.readObject();
            System.out.println(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
